package com.event.controller;

import com.event.pojo.entity.Category;
import com.event.result.Result;
import com.event.service.CategoryService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/category")
@Slf4j
public class CategoryController {
	
	
	@Resource
	private CategoryService categoryService;
	
	/**
	 * 新增分类
	 */
	@PostMapping
	public Result<?> addCategory(@RequestBody Category category) {
		log.info("新增文章分类：{}", category);
		categoryService.addCategory(category);
		return Result.success();
	}
	
	/**
	 * 根据用户id查询分类
	 */
	@GetMapping
	public Result<List<Category>> getCategoryList(Integer id) {
		log.info("根据用户id查询分类：{}", id);
		return Result.success(categoryService.getCategoryList(id));
	}
	
	/**
	 * 根据分类id获取分类
	 */
	@GetMapping("/detail")
	public Result<Category> getCategoryDetail(Integer id) {
		log.info("根据分类id获取分类：{}", id);
		return Result.success(categoryService.getById(id));
	}
	
	/**
	 * 更新分类
	 */
	@PutMapping
	public Result<?> updateCategory(@RequestBody Category category) {
		log.info("更新分类：{}", category);
		categoryService.updateCategory(category);
		return Result.success();
	}
	
	/**
	 * 删除分类
	 */
	@DeleteMapping
	public Result<?> deleteCategory(Integer id) {
		log.info("删除分类：{}", id);
		categoryService.removeById(id);
		return Result.success();
	}
}
